<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:rich="http://richfaces.org/rich">
    <style type="text/css">
        input[type='submit']{
            margin: 3px 5px 3px 5px;
            padding:3px 5px 3px 5px;
        }
        .treeRow{
            vertical-align:top;
        }
        .irow{
            padding:4px 3px 4px 3px;
            margin:2px 3px 2px 3px;
        }
        #cateAssetTable.tr{
            padding:4px 3px 4px 3px;
            margin:2px 3px 2px 3px;
        }
        #cateAssetTable td{
            padding:4px 3px 4px 3px;
            margin:2px 3px 2px 3px;
        }
        .top{
            vertical-align: top;
        }
    </style>
    <h:form>
        <rich:panel header="采购生成资产" styleClass="content-hight">
            <rich:messages/>
            <h:panelGroup id="editArea">
                <rich:toolbar  itemSeparator="Grid">
                    <rich:toolbarGroup id="tolbar">
                        <a4j:commandButton value="生成资产"
                                           action="#{buidAssetFromProcure.buildFromProcure}"
                                           render="@this,sasetEditGroup"
                                           onclick="this.disabled='true';"/>
                        <a4j:commandButton value="保存"
                                           action="#{buidAssetFromProcure.saveAssetFromProcure}"
                                           render="@this,cateGroup"
                                           onclick="this.disabled='true';"/>
                    </rich:toolbarGroup>
                </rich:toolbar>
                <h:panelGroup id="cateGroup">
                    <rich:dataScroller for="cateAssetTable"/>
                    <div style="width:750px;overflow:auto;">
                        <rich:dataTable id="cateAssetTable" value="#{buidAssetFromProcure.cateModel}" var="asset"
                                        style="width:1200px"
                                        rows="5">
                            <f:facet name="header">
                                <h:outputText value="资产生成" />
                            </f:facet>
                            <rich:column>
                                <f:facet name="header">选择</f:facet>
                                    <h:selectBooleanCheckbox value="#{asset.selected}">
                                        <a4j:ajax event="click" execute="@this" render="cateAssetTable"
                                                  listener="#{buidAssetFromProcure.deptChange}"/>
                                    </h:selectBooleanCheckbox>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">类目</f:facet>
                                <h:outputText value="#{asset.cateName}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">单价</f:facet>
                                <h:outputText value="#{asset.price}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">部门</f:facet>
                                <h:outputText value="#{asset.deptName}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">项目</f:facet>
                                <h:outputText value="#{asset.projName}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">数量</f:facet>
                                <h:outputText value="#{asset.count}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">购置日期</f:facet>
                                <rich:calendar value="#{asset.purchDate}"
                                               locale="zh_CN"
                                               datePattern="yyyy-MM-dd"
                                               inputSize="8"
                                               disabled="#{!asset.selected}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">质保日期</f:facet>
                                <rich:calendar value="#{asset.shelfLife}"
                                               locale="zh_CN"
                                               popup="true"
                                               datePattern="yyyy-MM-dd"
                                               inputSize="8"
                                               disabled="#{!asset.selected}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">型号</f:facet>
                                <h:inputText id="model" value="#{asset.model}" size="10" disabled="#{!asset.selected}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">品牌</f:facet>
                                <h:inputText value="#{asset.brand}" size="10" disabled="#{!asset.selected}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">厂商</f:facet>
                                <h:inputText value="#{asset.manufacture}" size="10" disabled="#{!asset.selected}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">使用状况</f:facet>
                                <h:selectOneMenu value="#{asset.useStatus}" disabled="#{!asset.selected}">
                                    <f:selectItem itemLabel="在用" itemValue="0"/>
                                    <f:selectItem itemLabel="报废" itemValue="1"/>
                                    <f:selectItem itemLabel="报损" itemValue="2"/>
                                    <f:selectItem itemLabel="其他" itemValue="3"/>
                                </h:selectOneMenu>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">使用人</f:facet>
                                <h:panelGroup id="assetPersonli">
                                    <h:selectOneMenu value="#{asset.person.cpsn_number}" disabled="#{!asset.selected}">
                                        <f:selectItem itemValue="" itemLabel="-请选择-"/>
                                        <f:selectItems value="#{asset.personSelectli}"/>
                                    </h:selectOneMenu>
                                </h:panelGroup>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">备注</f:facet>
                                <h:inputText value="#{asset.memo}" size="10" disabled="#{!asset.selected}"/>
                            </rich:column>
                        </rich:dataTable>
                    </div>
                </h:panelGroup>
                <h:panelGroup id="sasetEditGroup">
                    <rich:dataScroller for="assetInfo"/>
                    <div style="width:750px;overflow: auto">
                        <rich:dataTable value="#{buidAssetFromProcure.assetFromProcure}"
                                        var="asset" id="assetInfo"
                                        rowKeyVar="rowKey"
                                        style="max-height:260px; width:1400px;"
                                        rows="5">
                            <a4j:ajax event="rowdblclick" listener="#{buidAssetFromProcure.assetEditRowSelected(rowKey)}"/>
                            <f:facet name="header">
                                <h:outputText value="资产信息" />
                            </f:facet>
                            <rich:column>
                                <f:facet name="header">
                                    <h:panelGroup>
                                        <h:outputText value="资产编号"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:outputText  value="#{asset.assetCode}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:panelGroup>
                                        <outputText value="资产名称"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:inputText value="#{asset.assetName}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText  value="品牌"/>
                                </f:facet>
                                <h:inputText value="#{asset.brand}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText  value="规格型号"/>
                                </f:facet>
                                <h:inputText value="#{asset.model}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText  value="单价"/>
                                </f:facet>
                                <h:inputText value="#{asset.price}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText  value="购置日期"/>
                                </f:facet>
                                <rich:calendar value="#{asset.purchDate}"
                                               locale="zh_CN"
                                               datePattern="yyyy-MM-dd"
                                               inputSize="8"
                                               disabled="#{!asset.selected}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText  value="保管地点"/>
                                </f:facet>
                                <h:inputText value="#{asset.place}"/>
                            </rich:column>
                            <rich:column id="keeperCol">
                                <f:facet name="header">
                                    <h:outputText  value="保管人"/>
                                </f:facet>
                                <h:inputText id="keeperName"
                                    value="#{asset.keeper.cpsn_name}"
                                             ondblclick="#{rich:component('keeperPanel')}.show();"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText  value="使用人"/>
                                </f:facet>
                                <h:inputText 
                                    value="#{asset.person.cpsn_name}"
                                             ondblclick="#{rich:component('userPanel')}.show();"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText  value="使用状况"/>
                                </f:facet>
                                <h:selectOneMenu value="#{asset.useStatus}">
                                    <f:selectItem itemLabel="在用" itemValue="0"/>
                                    <f:selectItem itemLabel="报废" itemValue="1"/>
                                    <f:selectItem itemLabel="报损" itemValue="2"/>
                                    <f:selectItem itemLabel="其他" itemValue="3"/>
                                </h:selectOneMenu>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText  value="备注"/>
                                </f:facet>
                                <h:inputText value="#{asset.memo}"/>
                            </rich:column>
                        </rich:dataTable>
                    </div>
                </h:panelGroup>
            </h:panelGroup>
        </rich:panel>
    </h:form>
    <rich:popupPanel id="keeperPanel" autosized="true">
        <f:facet name="header">保管人</f:facet>
        <f:facet name="controls">
            <h:outputLink value="#" onclick="#{rich:component('keeperPanel')}.hide();
                                                   return false;">关闭</h:outputLink>
        </f:facet>
            <h:form>
                <rich:panel>
                    <div style="width:600px;min-height: 300px;">
                    <h:panelGrid columns="2" columnClasses="top,top">
                        <h:panelGroup>
                            <rich:tree value="#{departmentBean.rootNode}" var="idept"
                                       selectionType="ajax" toggleType="client"
                                       selectionChangeListener="#{personBean.treeSelected}"
                                       style="width:200px" render="tableGroup">
                                <rich:treeNode>
                                    <h:outputText value="[#{idept.data.code}]#{idept.data.name}" />
                                </rich:treeNode>
                            </rich:tree>
                        </h:panelGroup>                  
                        <h:panelGroup id="tableGroup">
                        <rich:dataScroller for="personinfo" execute="@this" render="tableGroup"
                                           maxPages="5"/>
                        <div style="width: 400px;overflow:auto;">
                            <rich:dataTable  value="#{personBean.personModel}"
                                             var="person"
                                             style="width:100%;margin-bottom: 5px;"
                                             rows="10"
                                             id="personinfo"
                                             styleClass="tableStyle"
                                             noDataLabel="无数据！">
                                <f:facet name="header">
                                    <h:outputText value="部门人员信息" />
                                </f:facet>                 
                                <rich:column>
                                    <a4j:commandLink value="选择"
                                                     action="#{buidAssetFromProcure.keeperSelected(person.cpsn_number,person.cpsn_name)}"
                                                     execute="@this"
                                                     render="sasetEditGroup"
                                                     oncomplete="#{rich:component('keeperPanel')}.hide();"/>
                                </rich:column>              
                                <rich:column>
                                    <f:facet name="header">
                                        <h:panelGroup>
                                            <h:outputText value="人员代码"/>
                                        </h:panelGroup>
                                    </f:facet>
                                    <h:outputText value="#{person.cpsn_number}"/>
                                </rich:column>
                                <rich:column >
                                    <f:facet name="header">
                                        <h:panelGroup>
                                            <h:outputText value="人员姓名"/>
                                        </h:panelGroup>
                                    </f:facet>
                                    <h:outputText  value="#{person.cpsn_name}" />
                                </rich:column>
                            </rich:dataTable>
                        </div>
                    </h:panelGroup>
                        </h:panelGrid>
                        </div>
                </rich:panel>
            </h:form>
    </rich:popupPanel>
    
    <rich:popupPanel id="userPanel" autosized="true">
        <f:facet name="header">使用人</f:facet>
        <f:facet name="controls">
            <h:outputLink value="#" onclick="#{rich:component('userPanel')}.hide();
                                                   return false;">关闭</h:outputLink>
        </f:facet>
            <h:form>
                <rich:panel>
                    <div style="width:600px;min-height: 300px;">
                    <h:panelGrid columns="2" columnClasses="top,top">
                        <h:panelGroup>
                            <rich:tree value="#{departmentBean.rootNode}" var="idept"
                                       selectionType="ajax" toggleType="client"
                                       selectionChangeListener="#{personBean.treeSelected}"
                                       style="width:200px" render="tableGroup">
                                <rich:treeNode>
                                    <h:outputText value="[#{idept.data.code}]#{idept.data.name}" />
                                </rich:treeNode>
                            </rich:tree>
                        </h:panelGroup>                  
                        <h:panelGroup id="tableGroup">
                            <rich:dataScroller for="personinfo" execute="@this" render="tableGroup" maxPages="5"/>
                        <div style="width: 400px;overflow:auto;">
                            <rich:dataTable  value="#{personBean.personModel}"
                                             var="person"
                                             style="width:100%;margin-bottom: 5px;"
                                             rows="10"
                                             id="personinfo"
                                             styleClass="tableStyle"
                                             noDataLabel="无数据！">
                                <f:facet name="header">
                                    <h:outputText value="部门人员信息" />
                                </f:facet>                 
                                <rich:column>
                                    <a4j:commandLink value="选择"
                                                     action="#{buidAssetFromProcure.userSelected(person.cpsn_number,person.cpsn_name)}"
                                                     execute="@this"
                                                     render="sasetEditGroup"
                                                     oncomplete="#{rich:component('userPanel')}.hide();"/>
                                </rich:column>              
                                <rich:column>
                                    <f:facet name="header">
                                        <h:panelGroup>
                                            <h:outputText value="人员代码"/>
                                        </h:panelGroup>
                                    </f:facet>
                                    <h:outputText value="#{person.cpsn_number}"/>
                                </rich:column>
                                <rich:column >
                                    <f:facet name="header">
                                        <h:panelGroup>
                                            <h:outputText value="人员姓名"/>
                                        </h:panelGroup>
                                    </f:facet>
                                    <h:outputText  value="#{person.cpsn_name}" />
                                </rich:column>
                            </rich:dataTable>
                        </div>
                    </h:panelGroup>
                    </h:panelGrid>
                        </div>
                </rich:panel>
            </h:form>
    </rich:popupPanel>
</ui:composition>